package com.xxx.video.dynamic.presenters;

import android.content.Context;

import androidx.annotation.NonNull;

import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.commen.views.AddFriendExtraMessageDialog;
import com.xxx.video.dynamic.beans.FriendListBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

public class PeopleNearbyPresenter extends BasePresenter<IPeopleNearbyView> {

    public PeopleNearbyPresenter(@NonNull Context context, IPeopleNearbyView baseView) {
        super(context, baseView);
    }

    /**
     * near by user
     *
     * @param page page
     * @param lon  lon
     * @param lan  lan
     */
    public void nearbyUser(String page, String lon, String lan) {
        NetWorkUtils.getInstance().nearbyUser(page, lon, lan, new CommonResponseListener<FriendListBean>() {
            @Override
            public void onSuccess(FriendListBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initNearByFriendList(successOb.page);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(3);
                }
            }
        });
    }

    public void addFriends(FriendListBean.PageBean.ListBean listBean, int position) {
        AddFriendExtraMessageDialog addFriendExtraMessageDialog = new AddFriendExtraMessageDialog(context);
        addFriendExtraMessageDialog.show();
        addFriendExtraMessageDialog.setOnButtonClickListener(message -> NetWorkUtils.getInstance().addFriends(listBean.userId, listBean.username, listBean.nickName, listBean.picUrl, message, new CommonResponseListener<BaseBean>() {

            @Override
            public void onSuccess(BaseBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().addFriendSuccess(position);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {

            }
        }));

    }
}
